﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MainMaster.master" AutoEventWireup="true"
    CodeFile="ContactSupplier.aspx.cs" Inherits="ContactSupplier" %>

<%@ Register Src="UserControl/fore/UC_Crumbs.ascx" TagName="UC_Crumbs" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CssLinkHolder" runat="Server">
    <link href="themes/css/formValidator.css" type="text/css" rel="Stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentHolder" runat="Server">
    <uc1:UC_Crumbs ID="UC_Crumbs1" runat="server" />
    <div class="postbuyingleads">
        <h1 class="tit">
            Send Inquiry
        </h1>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td height="30" align="right">
                    <strong>To:</strong>&nbsp;&nbsp;
                </td>
                <td>
                    <asp:Repeater ID="rptDataSource" runat="server">
                        <ItemTemplate>
                            <input type="checkbox" checked="checked" name="chkcontact" value="<%#Eval("Id") %>" />
                            <%#Eval("Subject") %>
                        </ItemTemplate>
                        <SeparatorTemplate>
                            <br />
                        </SeparatorTemplate>
                    </asp:Repeater>
                </td>
            </tr>
            <tr>
                <td height="30" align="right">
                    <span class="text_red">* </span><strong>Subject:</strong>&nbsp;&nbsp;
                </td>
                <td>
                    <input name="txtSubject" type="text" class="userinput" id="txtSubject" placeholder="Subject"
                        value="" style="width: 420px;">
                    <div id="txtSubjectTip" style="width: 220px; left: 430px;">
                    </div>
                </td>
            </tr>
            <tr>
                <td height="90" align="right" valign="top">
                    <span class="text_red">* </span><strong>Message:</strong>&nbsp;&nbsp;
                </td>
                <td>
                    <textarea name="txtMessage" rows="5" class="usertextarea" id="txtMessage" style="height: 78px;
                        width: 420px;"></textarea>
                    <div id="txtMessageTip" style="width: 220px; left: 430px;">
                    </div>
                </td>
            </tr>
            <%if (!this.HasLogin) {  %>
            <tr>
                <td height="30" align="right">
                    <span class="text_red">* </span><strong>Your Email:</strong>&nbsp;&nbsp;
                </td>
                <td>
                    <input type="text" name="txtEmail" placeholder="Your Email" id="txtEmail" class="userinput">
                    <div id="txtEmailTip" style="width: 220px; left: 430px;">
                    </div>
                </td>
            </tr>
            <tr>
                <td width="25%" height="30" align="right">
                    <span class="text_red">* </span><strong>Your Name:&nbsp;</strong>&nbsp;
                </td>
                <td width="75%">
                    <input name="txtName" type="text" class="userinput" id="txtName" placeholder="Your Name">
                    <div id="txtNameTip" style="width: 220px; left: 430px;">
                    </div>
                </td>
            </tr>
            <%} %>
            <tr>
                <td height="30" align="right">
                    <span class="text_red">* </span><strong>Country/Region:</strong>&nbsp;&nbsp;
                </td>
                <td>
                    <select id="dropdownCountry" name="dropdownCountry">
                        <option value="-1">--Please select country / region-- </option>
                        <asp:Repeater ID="rptCountrySource" runat="server">
                            <ItemTemplate>
                                <option value="<%#Eval("CountryId") %>">
                                    <%#Eval("Name")%></option>
                            </ItemTemplate>
                        </asp:Repeater>
                    </select>
                    <div id="dropdownCountryTip" style="width: 220px; left: 430px;">
                    </div>
                </td>
            </tr>
            <tr>
                <td height="30" align="right">
                    <strong>Attachment:</strong>&nbsp;
                </td>
                <td>
                    <label>
                        <input type="file" name="uploadAttach" id="postFile" />
                        <input type="hidden" id="uploadType" value="4" /><!--标识上传图片类型-->
                        <input type="hidden" name="hidfilepath" id="hidfilepath" /><!--上传成功后返回的图片名称-->
                    </label>
                    <img id="viewImg" style="display: none" />
                </td>
            </tr>
        </table>
        <div class="postbuysave">
            <input name="Submit" id="btnSubmit" type="submit" value="Send" class="userleftsub"></div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="JsHolder" runat="Server">
    <script type="text/javascript" src="themes/scripts/formValidator-4.0.1.min.js"></script>
    <script type="text/javascript" src="Themes/scripts/jquery.selecter.js"></script>
    <script type="text/javascript">
        (function ($) {
            if ($.uploadFile) return false; //防止JS重复加载
            $.fn.uploadFile = function (options) {
                this.each(function () {
                    if (!$.nodeName(this, 'INPUT')) { return; }
                    if (!this.uploadFile) {
                        var upload = new $.uploadFile(this, options);
                        if (upload.init()) {
                            this.uploadFile = upload;
                        }
                        else upload = null;
                    }
                });
            }

            $.uploadFile = function (input, options) {
                var _this = this;
                var _nextObj = null;

                if (options.isWatermark == null)
                    options.isWatermark = '0';

                this.init = function () {
                    $(input).hide();
                    _this.showForm();
                    //_this.showOneValue($(input).val());
                    return true;
                }

                this.showForm = function () {
                    _nextObj = $(input).next('div');
                    if (_nextObj.size() == 0 || _nextObj.eq(0).attr('class') != 'uploadfileContainer') {
                        $(input).after('<div class="uploadfileContainer"></div>');
                        _nextObj = $(input).next('.uploadfileContainer').eq(0);
                    }
                    else {
                        _nextObj = $(input).next('.uploadfileContainer').eq(0);
                        return;
                    }
                    _nextObj.append('<div class="uploadfileOne"><div class="uploadfileInfo"></div><iframe name="uploadfileForm" src="about:blank" frameborder="0" scrolling="no" style="height:40px; width:300px; " allowTransparency="true"></iframe></div>');
                    _nextObj.find('iframe').eq(0).bind('load', function () {
                        var _value = $(this).contents().find('body').html();
                        if (_value != "false" && _value != null && _value != "") {
                            _this.success(_value);
                        }
                    });

                    setTimeout(function () {
                        _nextObj.find('iframe').each(function () {
                            _this.showOneForm();
                        });
                    }, 250);
                }

                // 组装 form 和上传组件
                this.showOneForm = function () {

                    var type = $("#uploadType").val();
                    var url = "/handler/postFile.ashx";
                    //var t = $("#uploadtype").val();
                    var input = "";
                    input = "<input type=\"button\" class=\"upload_2\" name=\"upload\" value='选择' id=\"upload\" />"

                    var _objFrame = _nextObj.find('iframe').eq(0);
                    //   _objFrame.contents().find('head').append('<link href="/themes/default/css/StyleSheet.css" type="text/css" rel="stylesheet"/>');
                    _objFrame.contents().find('body').html('<div class="add"><div id="uploadCtr" ><form class="picForm" action="' + url + '" method="post" enctype="multipart/form-data"><input type="hidden" name="eType" value=' + type + ' /><input type="hidden" name="isReferrer" id="isReferrer" value="1"><input type="file" name="upfile" id="fileUpload"  /></form>' + input + '</div></div>');
                    _objFrame.contents().find('#fileUpload').bind('change', function () {
                        _this.postFile();
                        $(this).get(0).form.submit();
                    });
                }

                // 上传文件中样式
                this.postFile = function () {
                    //$(".uploadfileInfo").attr("style", "height:16px; width:100px; float:left;line-height:16px;");
                    _nextObj.find('.uploadfileInfo').eq(0).html('<img src="http://imagecn.gasgoo.com/sns/default/images/purchas/loading.gif" align="middle" />');
                    _nextObj.find('.uploadfileInfo').eq(0).show();
                    _nextObj.find('iframe').eq(0).hide();
                }

                // 存在图片
                this.showOneValue = function (value) {
                    if (value != '') {
                        var t = $("#type").val();
                        if (t == "Merchant" || t == "Stock") {
                            _nextObj.find('.uploadfileInfo').eq(0).html('<span style="float:left; height:13px; ">上传完成</span><a name="reupload" class="iconClose"></a>');
                        } else {
                            _nextObj.find('.uploadfileInfo').eq(0).html('<span style="float:left; height:13px; margin-top:9px;">上传完成</span><a name="reupload" style=" display: block;  float: left; height: 13px; margin:12px 0 0 5px; overflow: hidden; width: 12px;"><img src="http://imagecn.gasgoo.com/sns/default/images/fast/close.gif" alt="删除已上传的文件"/></a>');
                        }
                        _nextObj.find('.uploadfileInfo').eq(0).find('[name=reupload]').bind('click', function () {
                            _this.ReUpload();
                        });
                    }
                }

                // 重新上传
                this.ReUpload = function () {
                    _nextObj.find('.uploadfileOne').eq(0).find('img').remove();
                    _nextObj.find('.uploadfileInfo').eq(0).html('').hide();
                    _this.showOneForm();
                    _nextObj.find('iframe').eq(0).show();
                    $(input).val($(input).val());
                }

                // 请求成功
                this.success = function (msg) {
                    try {
                        uploadSuccess(eval("(" + msg + ")"));
                        _nextObj.find('.uploadfileInfo').eq(0).html("");
                    } catch (e) {
                        alert(e);
                        alert(msg);
                        _this.ReUpload();
                    }

                }
            }
        })(jQuery);

        $("#postFile").uploadFile({ key: 'img' });

        function uploadSuccess(fileEntity) {

            jQuery("#viewImg").attr("src", fileEntity.ImageUrl);
            jQuery("#viewImg").show();
            jQuery("#hidfilepath").val(fileEntity.FileID + fileEntity.FileExtension);
        }



        jQuery(function () {

            jQuery.formValidator.initConfig({ submitButtonID: "btnSubmit", autoTip: false, debug: false, onSuccess: function () { return true; }, onError: function () { } });
            jQuery("#dropdownCountry").formValidator({ onShow: " ", onFocus: " ", onCorrect: " " }).inputValidator({ min: 1, onError: "Country/Region is required" });
            jQuery("#txtEmail").formValidator({ onShow: " ", onFocus: " ", onCorrect: " " }).inputValidator({ min: 1, onError: "Your Email is required" })
            .regexValidator({ regExp: "^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$", onError: "Your Email is not valid" });
            jQuery("#txtSubject").formValidator({ onShow: " ", onFocus: " ", onCorrect: " " }).inputValidator({ min: 2, onError: "Subject is required" });
            jQuery("#txtMessage").formValidator({ onShow: " ", onFocus: " ", onCorrect: " " }).inputValidator({ min: 2, onError: "Message  is required" });
            jQuery("#txtName").formValidator({ onShow: " ", onFocus: " ", onCorrect: " " }).inputValidator({ min: 2, onError: "Your Name is required" });
        })
    </script>
</asp:Content>
